package cn.maihe.elg.operation.repository.entity;

import cn.maihe.framework.starter.base.sql.BaseEntity;
import cn.maihe.framework.starter.base.sql.MapperInterface;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@TableName("t_org_change_history")
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@MapperInterface("cn.maihe.elg.operation.repository.mapper.OrgChangeHistoryMapper")
public class OrgChangeHistoryDO extends BaseEntity {
    /**
     * 主键
     */
    @TableId(type = IdType.ID_WORKER)
    private Long id;

    /**
     * 机构主键id
     */
    @TableField(value = "org_id")
    private Long orgId;

    /**
     * 变更类型 0-新增 1-删除 2-编辑
     */
    @TableField(value = "operate_type")
    private String operateType;

    /**
     * 变更状态 0-成功 1-失败
     */
    @TableField(value = "operate_status")
    private String operateStatus;

    /**
     * 变更内容
     */
    @TableField(value = "operate_content")
    private String operateContent;

    /**
     * 变更时间
     */
    @TableField(value = "gmt_create", fill = FieldFill.INSERT)
    private Date gmtCreate;

    /**
     * 更新时间
     */
    @TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    /**
     * 变更用户
     */
    @TableField(value = "user_create", fill = FieldFill.INSERT)
    private String userCreate;

    /**
     * 更新用户
     */
    @TableField(value = "user_modified", fill = FieldFill.INSERT_UPDATE)
    private String userModified;

    public OrgChangeHistoryVo buildVo() {
        return new OrgChangeHistoryVo(id, orgId, operateType, operateStatus, operateContent, gmtCreate, gmtModified, userCreate, userModified);
    }

    public static OrgChangeHistoryDO of(OrgChangeHistoryVo vo) {
        return new OrgChangeHistoryDO(vo.getId(), vo.getOrgId(), vo.getOperateType(), vo.getOperateStatus(), vo.getOperateContent(), vo.getGmtCreate(), vo.getGmtModified(), vo.getUserCreate(), vo.getUserModified());
    }
}
